var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "id",
			name : "id",
			isSort:true,
		}, {
			colkey : "pro_title",
			name : "促销名称",
			isSort:true,
		}, {
			colkey : "pro_count",
			name : "促销数量规则",
			isSort:true,
		}, {
			colkey : "pro_money",
			name : "促销金额规则",
			isSort:true,
		}, {
			colkey : "pro_rate",
			name : "促销折扣率",
			isSort:true,
		},  {
			colkey : "ext",
			name : "促销说明",
			isSort:true,
		},{
			colkey : "pro_start",
			name : "活动开始时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		}, {
			colkey : "pro_end",
			name : "活动结束时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		}],
		jsonUrl : rootPath + '/promotion/detail/selectList',
		checkbox : true,
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	$("#addProDetail").click("click", function() {
		addProDetail();
	});
	$("#editProDetail").click("click", function() {
		editProDetail();
	});
	$("#delProDetail").click("click", function() {
		delProDetail();
	});
});
function addProDetail() {
	//一系列的校验
	//loadPage(rootPath+"/promotion/add");
	pageii = layer.open({
		title : "新增",
		type : 2,
		maxmin : true,
		resize :true,
		area : [ "60%", "85%" ],
		content : rootPath + '/promotion/detail/add'
	});
}
function editProDetail() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	
	//loadPage(rootPath+"/promotion/edit?id="+cbox);
	pageii = layer.open({
		title : "编辑",
		type : 2,
		maxmin : true,
		resize :true,
		area : ["60%", "85%" ],
		content : rootPath + '/promotion/detail/edit?id=' + cbox
	});
}
function delProDetail() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/promotion/detail/del';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		console.log( s);
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}
